#include "Reactor.hpp"
#include "Common.hpp"
#include "Socket.hpp"

static void Usage(std::string proc)
{
	std::cout << "Usage: " << proc << " port" << std::endl;
}
#define BACK_LOG 5

int main(int argc, char* argv[]) {
    if(argc != 2) {
        Usage(argv[0]);
		exit(1);
    }
    int port = atoi(argv[1]);

    int listen_sockfd = SocketMethod::SocketCreate();
    SetNonBlock(listen_sockfd);
    SetNonBlock(listen_sockfd);
    SocketMethod::SocketBind(listen_sockfd, port);
    SocketMethod::SocketListen(listen_sockfd, BACK_LOG);

    Reactor R;
    EventUnit evut;
    evut._sockfd = listen_sockfd;
    evut._R = &R;
    evut.RegisterCallback(accepter, nullptr, nullptr);
    R.AddEvent(listen_sockfd, EPOLLIN | EPOLLET, evut);

    R.loop();

    return 0;
}